﻿@{
    ViewBag.Title = "ประเภทการอนุมัติ";
    var context = new GERPContext(true);
    int? appPrcGrpId = ViewBag.appPrcGrpId;
    ApproveProcessGroup appPrcGrp = null;// context.ApproveProcessGroups.FirstOrDefault(o => o.AppPrcGrpId == appPrcGrpId);
    var allAppPrc = context.ApproveProcesses.Include(o => o.ApproveProcessGroup).Where(o=>o.RecordStatus != "D").OrderBy(o => o.AppPrcGrpId);
    var data = appPrcGrp == null ? allAppPrc : allAppPrc.Where(o=> o.AppPrcGrpId == appPrcGrpId);
    int i = 0;
}

<h4 class="header">ประเภทการอนุมัติ 
    @if(appPrcGrp != null)
    {
        <text>
            [ภายใต้ระบบ @appPrcGrp.Name <sup><a href="@Url.Action("Index")" title="แสดงทั้งหมด" style="color:red">x</a></sup>]
        </text>
    }
    &nbsp;&nbsp;&nbsp;&nbsp; @Html.ActionLink("เพิ่ม", "Create")
    @*<div class="right30">
        <a href="@Url.Action("Index", "ApproveProcessGroup")">ไปที่ระบบการอนุมัติ</a> 
    </div>*@
</h4>

<div class="BlockContent">
<table class="tablesorter">
    <thead>
        <tr>
            <th>AppPrcId</th>
            <th>ชื่อประเภทการอนุมัติ</th>
            <th>เงื่อนไข</th>
            <th>AppPrcGrpId</th>
            <th>Code</th>
            <th>ระบบการอนุมัติ</th> 
            @*<th>ตัวเลือกของประเภท</th>*@
            @*<th>ใช้งาน</th>*@
            <th>#</th>
        </tr>
    </thead>
    <tbody>
        
        @foreach(var p in data)
        {
            <tr>
                <td style=" text-align: center;">@p.AppPrcId</td>
                <td>
                    @if(p.RecordStatus == "U") {
                        <a href="@Url.Action("Detail", new {id=p.AppPrcId, ViewBag.appPrcGrpId})">@p.Name</a>
                    } else
                    {
                        <span style="color:silver">@p.Name</span>
                    }
                    @if(p.IsDefaultProcess)
                    {
                        @:&nbsp;<span style="color:darkorange">(Default)</span>
                    }
                </td>
                <td>
                    @{
                        var mapping = new GERPContext().ApproveProcessMappings.FirstOrDefault(o => o.AppPrcId == p.AppPrcId);
                        string wording = "";
                        if (mapping != null)
                        {
                            switch (mapping.TypeOfCompare)
                            {
                                case TypeOfCompare.LessThan:
                                    wording = "น้อยกว่า";
                                    break;
                                case TypeOfCompare.MoreThan:
                                    wording = "มากกว่า";
                                    break;
                                case TypeOfCompare.Equal:
                                    wording = "เท่ากับ";
                                    break;
                                case TypeOfCompare.LessThanOrEqual:
                                    wording = "ไม่เกิน";
                                    break;
                                case TypeOfCompare.MoreThanOrEqual:
                                    wording = "ตั้งแต่";
                                    break;
                                case TypeOfCompare.NotEqual:
                                    wording = "ไม่เท่ากับ";
                                    break;
                            }
                            @: @wording @mapping.ValueToCompare.ToString("#,##0.00")
                        } else
                        {
                            @:-
                        }
                    }
                </td>
                <td>@p.AppPrcGrpId</td>
                <td>
                @p.ApproveProcessGroup.Code 
                    </td>
                <td>
                    @p.ApproveProcessGroup.Name 
                </td>
                @*<td>
                    @{
                        p.ApproveProcessGroup.LoadMoreInformation();
                    }
                    <span title="@string.Join(",", from e in p.ApproveProcessGroup.Entities where e.AppPrcId == p.AppPrcId select e.Name)">
                        @p.ApproveProcessGroup.Entities.Count(o => o.AppPrcId == p.AppPrcId)
                    </span>
                </td>*@
                @*<td>
                    <input type="checkbox" disabled="disabled" @(p.RecordStatus == "U" ? "checked='checked'":"")/>
                </td>*@
                <td>
                    @if(p.RecordStatus == "U") {
                        <text>
                            <a href="@Url.Action("Detail", new {id= p.AppPrcId, ViewBag.appPrcGrpId})">ดูข้อมูล</a> | 
                            @Html.ActionLink("แก้ไข", "Update", new {id = p.AppPrcId, ViewBag.appPrcGrpId}) | 
                        </text>
                    }
                    @if(p.RecordStatus == "U"){
                        <a href="@Url.Action("Delete", new {id = p.AppPrcId, ViewBag.appPrcGrpId})" onclick="return confirm('หากมีคำขอที่ใช้งานระบบนี้อยู่ จะทำให้คำอนุมัตินั้นๆ ใช้ไม่ได้ ท่านต้องการยืนยันหรือไม่')">เลิกใช้</a>
                    } else
                    {
                        <a href="@Url.Action("Enable", new {id = p.AppPrcId, ViewBag.appPrcGrpId})" onclick="return confirm('ยืนยัน')">เปิดใช้</a>
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
    </div>

<div id="pager">
    @*<div class="right30" style="color:rgb(85, 85, 85); ">มีทั้งหมด @data.Count() ประเภท (ใช้อยู่ @data.Count(o=>o.RecordStatus == "U"))</div>*@
    <form>
        <img src="@Url.Content("~/Images/Icons/first.png")" class="first" />
        <img src="@Url.Content("~/Images/Icons/prev.png")" class="prev" />
        <input type="text" class="pagedisplay" style="text-align: center" />
        <img src="@Url.Content("~/Images/Icons/play.png")" class="next" />
        <img src="@Url.Content("~/Images/Icons/last.png")" class="last" />
        <select class="pagesize"> 
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="30">30</option>
            <option value="40">40</option>
            <option value="50" selected="selected">50</option>
        </select>
    </form>
</div>
<br/>

@section scripts{ 
    <script type="text/javascript">
        jQuery(function ($) {
            $("table.tablesorter").tablesorter({ widthFixed: true, widgets: ["zebra", "filter"] })
                .tablesorterPager({ container: $("#pager"), size: $(".pagesize option:selected").val() });
        });

    </script>
}